package com.fzshang.commen.util.zhifubao;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradePrecreateModel;
import com.alipay.api.request.AlipayTradePrecreateRequest;
import com.alipay.api.response.AlipayTradePrecreateResponse;

import java.io.IOException;

public class Zhifu {
    // 商户appid     // TODO: 2018/9/14  这里需要替换
    public static String APPID = "2021001126690266";
    // 私钥 pkcs8格式的
    //public static String RSA_PRIVATE_KEY = "此处省略若干字";
    // 服务器异步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
  //  public static String notify_url = "此处省略若干字";
    // 页面跳转同步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问 商户可以自定义同步跳转地址
    public static String MaChineNotify = "https://www.baidu.com";      // TODO: 2018/9/14  这里需要替换
    //充值成功通知地址
    public static String RechargeNotifyUrl = "http://www.fzshang.top:8081/app/userAgentInfo/rechargeSuccess";      // TODO: 2018/9/14  这里需要替换
  //  public static String H5_RETURN_URL = "http://f1xt81jc8n.51http.tech/user/login.html";      // TODO: 2018/9/14  这里需要替换
    // 请求网关地址             // TODO: 2018/9/14  这里需要替换
    public static String ALIURL = "https://openapi.alipaydev.com/gateway.do";
    // 编码
    public static String CHARSET = "UTF-8";
    // 返回格式
    public static String FORMAT = "json";
    // 商户私钥  对 公钥   和 阿里公钥      // TODO: 2018/9/14  这里需要替换
    public static String RSA2_Private_KEY = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCwNk7Jh8m5MB8Vx7yDmKk+MfrLvGOKV41zT8SXdO69YLxDJ1aPLG82XxReorlZX8nock5o7h3hK/MtsPo1FxPSgURoVaXbIVtTO4+v13xBrmRYqw9VlDsTGIcuOSqlloEUssjXOYWJu1H69UiYir5naKXyVNX72IXcTwbpoxDfxX1ALAfMPD1cQil8mEQAiBT6uCySJSibFmRK1BJTqTI/sGXh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s6qfSg3wVNaZXgplgmAruZBBY4puP+0JfpHV/dqaQIDAQAB";
    // 日志记录目录
    public static String log_path = "/log";
    // RSA2
    public static String SIGNTYPE = "RSA2";
    public static void zhifu( ) throws IOException, AlipayApiException {
        AlipayClient alipayClient = new DefaultAlipayClient(ALIURL, APPID, RSA2_Private_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY,SIGNTYPE); //获得初始化的AlipayClient        AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
        AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
        AlipayTradePrecreateModel alipayTradePrecreateModel=new AlipayTradePrecreateModel();
        alipayTradePrecreateModel.setOutTradeNo(OrderIdUtil.gen("测试",1L));
        alipayTradePrecreateModel.setTotalAmount("100");
        alipayTradePrecreateModel.setSubject("啊啊啊啊");
        request.setBizModel(alipayTradePrecreateModel);

        AlipayTradePrecreateResponse response = alipayClient.execute(request);
        System.err.println(response.getSubMsg());
        if(response.isSuccess()){
            System.out.println("调用成功");
            System.out.println(response.getQrCode());
        } else {
            System.out.println("调用失败");
        }
    }

public  static  void  main(String []args) throws IOException, AlipayApiException {
    zhifu();

}

}
